<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        const pm = new Promise((resolve, reject) => {
            try {
                console.log("开始请求A.....")
                throw new Error("网络出现问题!!!!")
                setTimeout(() => {
                    console.log("数据请求成功");
                    resolve({
                        token: "hskahdoqwhdlkash"
                    })
                }, 2000)
            } catch (e) {
                reject(e.message)
            }
        })

        /*
         -无论调用finally方法的promise实例是成功还是失败,都能执行finally回调函数
         -finally不接受promise实例的值
         -finally返回值
           -默认穿透,与调用finally的promise实例保持一致
           -当finally的回调函数返回一个失败的promise实例时
            finally的返回值和这个失败的promise实例保持一致
           -当finally的回调函数中报错,
            则finally返回失败的promise实例
            值为错误信息
        
        */

        //finally的回调函数是异步的
       const pmw = pm.finally(reason=>{
        console.log("finally",reason);//undefined
        throw new Error("finally报错")//后面的代码不执行
        return new Promise((resolve,reject)=>{
            // resolve("finally成功")
            // reject("finally失败")
        })
    })
        
    console.log("pmw",pmw)//与finally内部promise实例的失败状态返回值一致

    //    console.log("pmw",pmw);//与pm的返回值保持一致
    </script>
</body>

</html>